{% extends "base.html" %}
{% comment %}
Copyright 2010 Google Inc.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
{% endcomment %}

{% load i18n %}
{% block content %}
<h2>{% trans "Administration" %}</h2>
<p>
{% if user %}
  {% blocktrans with user.email as email %}You are currently signed in as <span class="email">{{email}}</span>.{% endblocktrans %}
  {% blocktrans with logout_url as logout_url %}<a href="{{logout_url}}">Sign out</a>{% endblocktrans %}
{% else %}
  {% blocktrans with login_url as login_url %}You are not currently signed in.  <a href="{{login_url}}">Sign in</a>{% endblocktrans %}
{% endif %}

<h2>Delete a record</h2>
<p>
<form method="post" class="admin">
  {{env.subdomain_field_html|safe}}
  <input type=hidden name=operation value=delete>
  person_record_id: <input name="id" id="id" size=50 value="{{id}}">
  <input type=submit value="Delete (with confirmation)">
</form>

<h2>Configure subdomains</h2>

<script>
  function $(id) {
    return document.getElementById(id);
  }
  function subdomain_selected() {
    if ($('subdomain_select').value == '__new__') {
      $('subdomain_create').style.display = 'inline';
    } else {
      $('subdomain_select').form.submit();
    }
  }
</script>

<p>
  <form method="get" style="display: inline-block" class="admin">
    Select a subdomain:
    <select name="subdomain" id="subdomain_select"
         onchange="subdomain_selected()">
      {% for subdomain in subdomains %}
        <option value="{{subdomain.key.name}}"
          {% ifequal subdomain.key.name env.subdomain %}
            selected
          {% endifequal %}
        >
          {{subdomain.key.name}}
        </option>
      {% endfor %}
      <option value="__new__">Create new...</option>
    </select>
  </form>
  <form id="subdomain_create" method="post" style="display: none" class="admin">
    <input type="hidden" name="operation" value="subdomain_create">
    <input name="subdomain_new" id="subdomain_new" size=15
      ><code>.{{env.parent_domain}}</code>
    <input type="submit" value="Create">
  </form>

<h2>Edit settings for
<a href="{{start_url}}">
{{env.subdomain}}.{{env.parent_domain}}</a></h2>

<form id="subdomain_save" method="post" class="admin">
  <fieldset>
    <legend>General</legend>
    <div class="config">
      <label for="language_menu_options">
        Languages in the language menu (JSON list):
      </label>
      <div class="response">
        <input name="language_menu_options" size=60 id="language_menu_options"
            value="{{config_json.language_menu_options}}">
      </div>
    </div>
    <div class="config">
      <label for="subdomain_titles">
        Title in each language (JSON dictionary):
      </label>
      <div class="response">
        <textarea name="subdomain_titles" rows=4 cols=80
>{{config_json.subdomain_titles}}</textarea>
      </div>
    </div>
    <div class="config">
      <label for="keywords">
        Keywords in all languages (keywords separated by commas):
      </label>
      <div class="response">
        <textarea name="keywords" rows=4 cols=80
>{{config.keywords|default:""}}</textarea>
      </div>
    </div>
  </fieldset>
  <fieldset>
    <legend>Forms</legend>
    <div class="config">
      <div class="option">
        <input type="radio" name="use_family_name" value="true"
            id="use_family_name_true"
            {{config.use_family_name|yesno:"checked,"}}>
        <label for="use_family_name_true">
          Use both given and family name fields
        </label>
      </div>
      <div class="option">
        <input type="radio" name="use_family_name" value="false"
            id="use_family_name_false"
            {{config.use_family_name|yesno:",checked"}}>
        <label for="use_family_name_false">
          Use only a single name field
        </label>
      </div>
    </div>

    <div class="config">
      <div class="option">
        <input type="radio" name="family_name_first" value="false"
            id="family_name_first_false"
            {{config.family_name_first|yesno:",checked"}}>
        <label for="family_name_first_false">
          Show given name first, then family name
        </label>
      </div>
      <div class="option">
        <input type="radio" name="family_name_first" value="true"
            id="family_name_first_true"
            {{config.family_name_first|yesno:"checked,"}}>
        <label for="family_name_first_true">
          Show family name first, then given name
        </label>
      </div>
    </div>

    <div class="config">
      <div class="option">
        <input type="radio" name="use_alternate_names" value="false"
            id="use_alternate_names_false"
            {{config.use_alternate_names|yesno:",checked"}}>
        <label for="use_alternate_names_false">
          Don't use alternate name fields (e.g. readings of Japanese names)
        </label>
      </div>
      <div class="option">
        <input type="radio" name="use_alternate_names" value="true"
            id="use_alternate_names_true"
            {{config.use_alternate_names|yesno:"checked,"}}>
        <label for="use_alternate_names_true">
          Use alternate name fields (e.g. readings of Japanese names)
        </label>
      </div>
    </div>

    <div class="config">
      <div class="option">
        <input type="radio" name="use_postal_code" value="true"
            id="use_postal_code_true"
            {{config.use_postal_code|yesno:"checked,"}}>
        <label for="use_postal_code_true">
          Use the postal code field
        </label>
      </div>
      <div class="option">
        <input type="radio" name="use_postal_code" value="false"
            id="use_postal_code_false"
            {{config.use_postal_code|yesno:",checked"}}>
        <label for="use_postal_code_false">
          Hide the postal code field
        </label>
      </div>
    </div>

    <div class="config">
      <div class="option">
        <input type="radio" name="min_query_word_length" value="1"
            id="min_query_word_length_1"
            {% ifequal config.min_query_word_length 1 %}
              checked
            {% endifequal %}
        >
        <label for="min_query_word_length_1">
          Accept queries with only 1 character
        </label>
      </div>
      <div class="option">
        <input type="radio" name="min_query_word_length" value="2"
            id="min_query_word_length_2"
            {% ifnotequal config.min_query_word_length 1 %}
              checked
            {% endifnotequal %}
        >
        <label for="min_query_word_length_2">
          Require query words to have at least 2 characters
        </label>
      </div>
    </div>
  </fieldset>

  <fieldset>
    <legend>Map options</legend>
    <div class="config">
      <label for="map_default_zoom">Default zoom level (integer):</label>
      <div class="response">
        <input name="map_default_zoom" id="map_default_zoom" size=24
            value="{{config_json.map_default_zoom}}">
      </div>
    </div>
    <div class="config">
      <label for="map_default_center">
        Default center [latitude north, longitude east]:
      </label>
      <div class="response">
        <input name="map_default_center" id="map_default_center" size=24
            value="{{config_json.map_default_center}}">
      </div>
    </div>
    <div class="config">
      <label for="map_default_center">
        Map size in pixels [width, height]:
      </label>
      <div class="response">
        <input name="map_size_pixels" id="map_size_pixels" size=24
            value="{{config_json.map_size_pixels}}">
      </div>
    </div>
  </fieldset>

  <fieldset>
    <legend>Access control</legend>
    <div class="config">
      <div class="option">
        <input type="radio" name="search_auth_key_required" value="false"
            id="search_auth_key_required_false"
            {{config.search_auth_key_required|yesno:",checked"}}>
        <label for="search_auth_key_required_false">
          Allow anyone to use the search API
        </label>
      </div>
      <div class="option">
        <input type="radio" name="search_auth_key_required" value="true"
            id="search_auth_key_required_true"
            {{config.search_auth_key_required|yesno:"checked,"}}>
        <label for="search_auth_key_required_true">
          Require an authorization key to use the search API
        </label>
      </div>
    </div>
    <div class="config">
      <div class="option">
        <input type="radio" name="read_auth_key_required" value="false"
            id="read_auth_key_required_false"
            {{config.read_auth_key_required|yesno:",checked"}}>
        <label for="read_auth_key_required_false">
          Allow anyone to use the read API and read the feeds
        </label>
      </div>
      <div class="option">
        <input type="radio" name="read_auth_key_required" value="true"
               id="read_auth_key_required_true"
               {{config.read_auth_key_required|yesno:"checked,"}}>
        <label for="read_auth_key_required_true">
          Require an authorization key to use the read API and read the feeds
        </label>
      </div>
    </div>
  </fieldset>

  <fieldset>
    <legend>Deactivation</legend>
    <div class="config">
      <div class="option">
        <input type="radio" name="deactivated" value="false"
            id="deactivated_false" {{config.deactivated|yesno:",checked"}}>
        <label for="deactivated_false">
          Activated (normal)
        </label>
      </div>
      <div class="option">
        <input type="radio" name="deactivated" value="true"
            id="deactivated_true" {{config.deactivated|yesno:"checked,"}}>
        <label for="deactivated_true">
          Deactivated (replace all pages with the message below)
        </label>
      </div>
    </div>
    <div class="config">
      <label for="deactivation_message_html">
        Deactivation message (HTML):</label>
      <div class="response">
        <textarea name="deactivation_message_html" rows=6 cols=80
>{{config.deactivation_message_html|default:""}}</textarea>
      </div>
    </div>
  </fieldset>
  <fieldset>
    <legend>Optional custom messages</legend>
    <div class="config">
      <label for="main_page_custom_htmls">
        Custom message for main page in each language
        (JSON dictionary with HTML values):
      </label>
      <div class="response">
        <textarea name="main_page_custom_htmls" rows=10 cols=80
>{{config_json.main_page_custom_htmls}}</textarea>
      </div>
    </div>
    <div class="config">
      <label for="results_page_custom_htmls">
        Custom message for search results page in each language
        (JSON dictionary with HTML values):
      </label>
      <div class="response">
        <textarea name="results_page_custom_htmls" rows=10 cols=80
>{{config_json.results_page_custom_htmls}}</textarea>
      </div>
    </div>
    <div class="config">
      <label for="view_page_custom_htmls">
        Custom message for person record view page in each language
        (JSON dictionary with HTML values):
      </label>
      <div class="response">
        <textarea name="view_page_custom_htmls" rows=10 cols=80
>{{config_json.view_page_custom_htmls}}</textarea>
      </div>
    </div>
    <div class="config">
      <label for="seek_query_form_custom_htmls">
        Custom message for the query form when role=seek in each language
        (JSON dictionary with HTML values):
      </label>
      <div class="response">
        <textarea name="seek_query_form_custom_htmls" rows=10 cols=80
>{{config_json.seek_query_form_custom_htmls}}</textarea>
      </div>
    </div>
  </fieldset>

  <p>
    <input type="hidden" name="operation" value="subdomain_save">
    <input type="submit" value="Save these settings">
</form>
{% endblock %}
